package thread.day1;

/*
多线程的创建和调用
	创建两个线程，一个遍历20以内的奇数，一个遍历偶数
 */
public class ThreadCreate {
    public static void main(String[] args) {
        threadA t1 = new threadA();
        threadB t2 = new threadB();
        t1.start();
        t2.start();

        //如果这个变量后面用不到了，只用这一次，用匿名子类比较好
        //创建Thread的匿名子类的方法
//		new Thread(){
//			@Override
//			public void run() {
//				...
//			}
//		}.start();
    }
}

class threadA extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + "i = " + i);
                try {
                    sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}

class threadB extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            if (i % 2 != 0) {
                System.out.println(Thread.currentThread().getName() + "i = " + i);
                try {
                    sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}